package com.zhz.elasticjob.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.zhz.elasticjob.annotation.ElasticSimpleJob;
import com.zhz.elasticjob.listener.ZhzListener;
import com.zhz.elasticjob.strategy.ZhzJobShardingStrategy;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * @program: schedule
 * @description: 简单的任务
 * @author: zhanghz001
 * @create: 2021-08-05 09:53
 **/
@Slf4j
// @Component
@ElasticSimpleJob(name = "simpleJob",
        cron = "0/10 * * * * ?",
        shardingTotalCount = 10,
        overwrite = true,
        listeners = {ZhzListener.class},
        jobShardingStrategy = ZhzJobShardingStrategy.class,
        failover = true,
        monitorExecution = true)
public class MySimpleJob implements SimpleJob {
    @SneakyThrows
    @Override
    public void execute(ShardingContext shardingContext) {
        // TimeUnit.SECONDS.sleep(11);
        log.info("simpleJob 任务执行了,分片项: {} , 总分片 : {}",
                shardingContext.getShardingItem(),
                shardingContext.getShardingTotalCount());
        
    }
}
